#include "componentstab.h"

ComponentsTab::ComponentsTab(AED_Archtype *arch,ImageManager *manager, ImageModel *img_model, QWidget *parent) :
    QWidget(parent),m_arch(arch)
{
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setAlignment(Qt::AlignTop);
    this->setLayout(mainLayout);

    m_renderComp = new RenderCompWidget(0,manager, img_model);
    m_renderComp->setHidden(true);
    QPushButton *renderBut = new QPushButton("Render");
    renderBut->setCheckable(true);
    renderBut->setChecked(false);
    connect(renderBut,SIGNAL(toggled(bool)),m_renderComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(renderBut);
    mainLayout->addWidget(m_renderComp);


    m_physicsComp = new PhysicsCompWidget(0);
    m_physicsComp->setHidden(true);
    QPushButton *physicsBut = new QPushButton("Physics");
    physicsBut->setCheckable(true);
    physicsBut->setChecked(false);
    connect(physicsBut,SIGNAL(toggled(bool)),m_physicsComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(physicsBut);
    mainLayout->addWidget(m_physicsComp);

    m_keyComp = new KeyboardCompWidget(0);
    m_keyComp->setHidden(true);
    QPushButton *keyBut = new QPushButton("Keyboard");
    keyBut->setCheckable(true);
    keyBut->setChecked(false);
    connect(keyBut,SIGNAL(toggled(bool)),m_keyComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(keyBut);
    mainLayout->addWidget(m_keyComp);

    m_mouseComp = new MouseCompWidget(0);
    m_mouseComp->setHidden(true);
    QPushButton *mouseBut = new QPushButton("Mouse");
    mouseBut->setCheckable(true);
    mouseBut->setChecked(false);
    connect(mouseBut,SIGNAL(toggled(bool)),m_mouseComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(mouseBut);
    mainLayout->addWidget(m_mouseComp);

    m_alwaysComp = new AlwaysCompWidget(0);
    m_alwaysComp->setHidden(true);
    QPushButton *alwaysBut = new QPushButton("Always");
    alwaysBut->setCheckable(true);
    alwaysBut->setChecked(false);
    connect(alwaysBut,SIGNAL(toggled(bool)),m_alwaysComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(alwaysBut);
    mainLayout->addWidget(m_alwaysComp);

    m_soundComp = new SoundCompWidget(0);
    m_soundComp->setHidden(true);
    QPushButton *soundBut = new QPushButton("Sound");
    soundBut->setCheckable(true);
    soundBut->setChecked(false);
    connect(soundBut,SIGNAL(toggled(bool)),m_soundComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(soundBut);
    mainLayout->addWidget(m_soundComp);


    m_psysComp = new ParticleSystemCompWidget(0);
    m_psysComp->setHidden(true);
    QPushButton *psysBut = new QPushButton("Particle System");
    psysBut->setCheckable(true);
    psysBut->setChecked(false);
    connect(psysBut,SIGNAL(toggled(bool)),m_psysComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(psysBut);
    mainLayout->addWidget(m_psysComp);


    m_partComp = new ParticleCompWidget(0);
    m_partComp->setHidden(true);
    QPushButton *partBut = new QPushButton("Particle");
    partBut->setCheckable(true);
    partBut->setChecked(false);
    connect(partBut,SIGNAL(toggled(bool)),m_partComp,SLOT(setVisible(bool)));
    mainLayout->addWidget(partBut);
    mainLayout->addWidget(m_partComp);

    setArchtype(arch);
}

void ComponentsTab::setArchtype(AED_Archtype* arch){
    m_arch = arch;
    if(m_arch){
        m_renderComp->setComp(m_arch->GetRenderComp());
        m_physicsComp->setComp(m_arch->GetPhysicsComp());
        m_keyComp->setComp(m_arch->GetKeyboardComp());
        m_mouseComp->setComp(m_arch->GetMouseComp());
        m_alwaysComp->setComp(m_arch->GetAlwaysComp());
        m_soundComp->setComp(m_arch->GetSoundComp());
        m_psysComp->setComp(m_arch->GetParSysComp());
        m_partComp->setComp(m_arch->GetParticleComp());
    }else{
        m_renderComp->setComp(0);
        m_physicsComp->setComp(0);
        m_keyComp->setComp(0);
        m_mouseComp->setComp(0);
        m_alwaysComp->setComp(0);
        m_soundComp->setComp(0);
        m_psysComp->setComp(0);
        m_partComp->setComp(0);
    }

}
